﻿using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Ooaavee.TestTools
{
    /// <summary>
    /// Used to give parameters to a test method.
    /// </summary>
    /// <remarks>
    /// This attribute can be specified on a method.
    /// </remarks>
    [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "")]
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    public class TestParametersAttribute : Attribute
    {
        private readonly List<object> _parameters = new List<object>();

        /// <summary>
        /// Initializes a new instance of the TestParametersAttribute class.
        /// </summary>
        public TestParametersAttribute()
        {
        }

        /// <summary>
        /// Initializes a new instance of the TestParametersAttribute class.
        /// </summary>
        /// <param name="parameters">test parameters</param>
        public TestParametersAttribute(params object[] parameters)
        {
            _parameters.AddRange(parameters);
        }

        /// <summary>
        /// Gets or sets the object that contains data about the attribute.
        /// </summary>
        public virtual object Tag { set; get; }

        /// <summary>
        /// Gets parameters for a test method.
        /// </summary>
        /// <param name="testClass">the name of the calling test class</param>
        /// <param name="testMethod">the name of the calling test method</param>
        /// <returns>parameters</returns>
        public virtual ReadOnlyCollection<object> GetParameters(string testClass, string testMethod)
        {
            if (testClass == null)
            {
                throw new ArgumentNullException("testClass");
            }

            if (testMethod == null)
            {
                throw new ArgumentNullException("testMethod");
            }

            return _parameters.AsReadOnly();
        }
    }
}